package com.wn.utils;

import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class Base64JDK {

    private static final String x = "MTE2LjMyMTYyMzg4MTE=";
    private static final String y = "NDAuMDY2NDE0MTA4MjA1=";

    public static void main( String[] args ) {
        try {
            // BASE64加密
//            BASE64Encoder encoder = new BASE64Encoder();
//            String data = encoder.encode(DATA.getBytes());
//            System.out.println("BASE64加密：" + data);

            // BASE64解密
            BASE64Decoder decoder = new BASE64Decoder();
            byte[] bx = decoder.decodeBuffer(x);
            System.out.println("BASE64解密：" + new String(bx));

            byte[] by = decoder.decodeBuffer(y);
            System.out.println("BASE64解密：" + new String(by));

            // 结果
            // BASE64加密：Y29tLmJhc2U2NC5kZW1v
            // BASE64解密：com.base64.demo
        } catch (Exception e) {
            System.out.println("BASE64加解密异常");
            e.printStackTrace();
        }
    }
}
